
/*
    Software License

    Copyright (C) 2021-05-24  Xoronos

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/*
    Liabilities

    The software is provided "AS IS" without any warranty of any kind, either expressed,
    implied, or statutory, including, but not limited to, any warranty that the software
    will conform to specifications, any implied warranties of merchantability, fitness
    for a particular purpose, and freedom from infringement, and any warranty that the
    documentation will conform to the software, or any warranty that the software will
    be error free.

    In no event shall Xoronos be liable for any damages, including, but not limited to,
    direct, indirect, special or consequential damages, arising out of, resulting from,
    or in any way connected with this software, whether or not based upon warranty,
    contract, tort, or otherwise, whether or not injury was sustained by persons or
    property or otherwise, and whether or not loss was sustained from, or arose out of
    the results of, or use of, the software or services provided hereunder.

    To request the provided software under a different license you can contact us at
    support@xoronos.com
*/

#ifndef XORON_SETTINGS_H
#define XORON_SETTINGS_H

#include <stdbool.h>
#include <stdio.h>
#include "xrn_lib_interposer.h"

#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#define XRN_MAX_DECOYS 254

typedef struct common_settings_t {
    FILE *fpmatrix;
    FILE *fpmatrix_comp;
    xrn_crypto_extra_settings_t xrn_crypto_extra_settings;

    char enc_password_not_req;
    char dec_password_set;

    FILE *fpresponse;
    FILE *logerr;
    FILE *logwar;
    FILE *loginfo;
    FILE *logdbg;
    uint32_t debug_seed;
    uint8_t enc_no_run_war;
    uint8_t dec_no_run_war;
    uint8_t enc_no_dis_war;
    uint8_t dec_no_dis_war;

} common_settings_t;

typedef struct mk_mproof_b_t {
    FILE *mproof;
    FILE *mkeyresp;

} mk_mproof_b_t;

typedef struct mk_mproof_c_t {
    FILE *cert;
    FILE *mproof;

} mk_mproof_c_t;

typedef struct mk_mproof_s_t {
    FILE *pt;
    FILE *sig;
    FILE *mproof;

} mk_mproof_s_t;

typedef struct arithmetic_settings_t {

    FILE *fppoint;
    FILE *fpbinomial_key;
    FILE *fpmonomial_key;
    FILE *fpstart_point;
    FILE *fpmonomial_commitment;
    FILE *fpbinomial_commitment;
    FILE *fpmonomial_response;
    FILE *fpmonomial_proof;
    FILE *fpmonovalent_key;
    FILE *fppolyvalent_proof;
    FILE *fppolyvalent_key;
    FILE *fpsym_signature;
    FILE *fpasy_signature;
    FILE *fpring_signature;
    FILE *fphash;
    FILE *fpsym_certificate;
    FILE *fpasy_certificate;

} arithmetic_settings_t;

typedef struct miner_rnd_settings_t {
    FILE *fp;
    float prob;
    uint32_t max_try;
    uint8_t mode;
} miner_rnd_settings_t;

typedef struct miner_ot_settings_t {

    FILE *fp;
    int32_t minn;
    int32_t maxn;
    uint8_t mode;
    uint32_t max_try;
} miner_ot_settings_t;

typedef struct dumpencodingparameters_t {
    FILE *fp;
} dumpencodingparameters_t;

typedef struct xm_dec_t {

    FILE *fpw;
} xm_dec_t;

typedef struct xm_det_prm_t {

    FILE *fpw;

} xm_det_prm_t;

typedef struct xm_prm_t {
    FILE *fpw;
} xm_prm_t;

typedef struct xkey_settings_t {

    FILE *mkey;
    FILE *bkey;

} xkey_settings_t;

typedef struct mk_sp_t {
    FILE *fpgenerator;

} mk_sp_t;

typedef struct ess_settings_t {

    FILE *fpblockin;
    FILE *fpblockout;

} ess_settings_t;

typedef struct dss_settings_t {
    FILE *fpblockin;
    FILE *fpblockout;

} dss_settings_t;

typedef struct eas_settings_t {

    FILE *fpblockin;
    FILE *fpblockout;

} eas_settings_t;

typedef struct das_settings_t {
    FILE *fpblockin;
    FILE *fpblockout;

} das_settings_t;

typedef struct ringsig_gen_t {
    FILE *fpinput;
    FILE *fpdecoys[XRN_MAX_DECOYS];
    FILE *receiver_mkey;
    FILE *fpsignature;
    uint16_t ndecoys;

} ringsig_gen_t;

typedef struct ringsig_perm_t {
    FILE *fpsigner_bkey;
    FILE *fpverifier_bkey;
    FILE *fpsigner_rsig;
    FILE *fpverifier_rsig;
    FILE *fppermuted_rsig;
} ringsig_perm_t;

typedef struct ringsig_ver_t {
    FILE *fpinput;
    FILE *fpdecoys[XRN_MAX_DECOYS];
    FILE *sender_bkey;

} ringsig_ver_t;

typedef struct split_s_t {
    FILE *fpinput;
    FILE *fpoutsolution;
    FILE *fpoutchallenge;

} split_s_t;

typedef struct join_t {
    FILE *fpoutsolution;
    FILE *fpoutchallenge;
    FILE *fpout;

} join_t;

typedef struct hash_file_t {
    FILE *fpin;
    FILE *fpout;
} hash_file_t;

typedef struct sig_sym_t {
    FILE *plain_text;
    FILE *signature;

} sig_sym_t;

typedef struct sig_asym_t {
    FILE *fpin;
    FILE *fpout;

} sig_asym_t;

typedef struct ver_sig_asym_t {
    FILE *fpin;
    FILE *mkey;
    FILE *fpsig;

} ver_sig_asym_t;

typedef struct ver_sig_sym_t {
    FILE *fpin;
    FILE *mkey;
    FILE *fpsig;

} ver_sig_sym_t;

typedef struct keyxchg_t {

    FILE *bke;
    FILE *outmks;

} keyxchg_t;

typedef struct verify_signature_proof_t {
    FILE *fpplaintext;

} verify_signature_proof_t;

typedef struct comm_bkey_t {
    FILE *bkey;
    FILE *bkeycomm;
    FILE *mkeycomm;

} comm_bkey_t;

typedef struct comm_cert_t {
    FILE *cert;
    FILE *bkeycomm;
    FILE *mkeycomm;

} comm_cert_t;

typedef struct mk_mresp_t {
    FILE *mresp;

} mk_mresp_t;

typedef struct comm_sig_t {
    FILE *binomial_commitment;
    FILE *monomial_commitment;
    FILE *plain_text;
} comm_sig_t;

typedef struct hash_cmp_settings_t {
    FILE *fpin;

} hash_cmp_settings_t;

typedef struct pnrg_t {
    FILE *sp;

} pnrg_t;

typedef struct xrn_point_settings_t {
    FILE *xp;

} xrn_point_settings_t;

typedef struct cert_sym_t {
    char *subj;
    time_t start_v;
    time_t stop_v;
    FILE *fpmonovalent_key;
    FILE *cert;

} cert_sym_t;

typedef struct cert_asym_t {
    char *subj;
    time_t start_v;
    time_t stop_v;
    FILE *fpbinomial_key;
    FILE *cert;

} cert_asym_t;

typedef struct check_asymmetric_signature_t {
    FILE *fpplaintext;
} check_asymmetric_signature_t;

typedef struct make_checksum_t {
    FILE *plain_text;
    FILE *checksum;
} make_checksum_t;

typedef struct check_blocks_t {
    FILE *input;
} check_blocks_t;

typedef struct conv_type_t {
    FILE *in;
    FILE *out;
    uint32_t typein;
    uint32_t typeout;

} conv_type_t;

typedef struct enc_settings_t {
    FILE *in;
    FILE *out;

} enc_settings_t;

typedef struct print_header_t {
    FILE *in;

} print_header_t;

typedef struct strip_header_t {
    FILE *plaintext;
    FILE *file;

} strip_header_t;

typedef struct merge_header_t {
    FILE *blockfiles[XRN_MAX_MERGE_PARALLELISM];
    uint8_t nblocks;
    FILE *mergedblockfile;

} merge_header_t;

typedef struct make_block_t {
    FILE *plaintext;
    FILE *blockfile;
    uint32_t tag;
    uint64_t offset;
    uint64_t length;

} make_block_t;

typedef struct make_monovalent_key_t {
    FILE *polyvalent_key_fpw;
    FILE *polyvalent_proof_fpw;
    FILE *monovalent_key_fpw;
    time_t start_timestamp;
    time_t end_timestamp;

} make_monovalent_key_t;

typedef struct monovalent_key_verification_t {
    FILE *polyvalent_proof_fpr;

} monovalent_key_verification_t;

typedef struct check_monomial_proof_t {
    FILE *fpmonomial_response;
} check_monomial_proof_t;

typedef struct check_monomial_proof_sym_sig_t {
    FILE *fpplain_text;
} check_monomial_proof_sym_sig_t;

typedef struct crc_settings_t {
    FILE *filein;
} crc_settings_t;

typedef struct extract_steganography_raw_t {
    FILE *fileembedded;
    FILE *fileraw;
} extract_steganography_raw_t;

typedef struct extract_steganography_block_t {
    FILE *fileembedded;
    FILE *fileblock;
} extract_steganography_block_t;

typedef struct make_steganography_raw_t {
    FILE *filesource;
    FILE *fileenvelop;
    FILE *fileembedded;
} make_steganography_raw_t;

typedef struct make_steganography_block_t {
    FILE *filesource;
    FILE *fileenvelop;
    FILE *fileembedded;
    uint8_t folding_en;
    uint64_t offset;
    uint64_t length;
    uint32_t tag;
} make_steganography_block_t;

typedef struct get_capacity_t {
    FILE *fileenvelop;
    uint8_t folding_en;
} get_capacity_t;

typedef struct exchange_polyvalent_key_t {
    FILE *fpext_monovalent_key;
    FILE *fppolyvalent_key;
} exchange_polyvalent_key_t;

typedef struct settings_t {
    //general settings
    void *xrnlib_dll;
    FILE *logfilept;
    int command;
    int force_append;
    int force_write;
    common_settings_t common_settings;
    arithmetic_settings_t arithmetic_settings;
    miner_rnd_settings_t miner_rnd_settings;
    miner_ot_settings_t miner_ot_settings;
    dumpencodingparameters_t dumpencodingparameters;
    xm_dec_t xm_dec;
    xm_prm_t xm_prm;
    xm_det_prm_t xm_det_prm;
    xkey_settings_t xkey_settings;
    mk_sp_t mk_sp;
    print_header_t print_header;
    strip_header_t strip_header;
    merge_header_t merge_header;
    make_block_t make_block;
    ess_settings_t ess_settings;
    dss_settings_t dss_settings;
    eas_settings_t eas_settings;
    das_settings_t das_settings;
    ringsig_gen_t ringsig_gen;
    ringsig_perm_t ringsig_perm;
    ringsig_ver_t ringsig_ver;
    ver_sig_asym_t ver_sig_asym;
    ver_sig_sym_t ver_sig_sym;
    check_monomial_proof_t check_monomial_proof;
    check_monomial_proof_sym_sig_t check_monomial_proof_sym_sig;
    check_asymmetric_signature_t check_asymmetric_signature;
    check_blocks_t check_blocks;
    make_checksum_t make_checksum;
    split_s_t split_s;
    join_t join_stream;
    hash_file_t hash_file;
    sig_sym_t sig_sym;
    sig_asym_t sig_asym;
    keyxchg_t keyxchg;
    verify_signature_proof_t verify_signature_proof;
    comm_bkey_t comm_bkey;
    comm_cert_t comm_cert;
    comm_sig_t comm_sig;
    mk_mresp_t mk_mresp;
    mk_mproof_b_t mk_mproof_b;
    mk_mproof_s_t mk_mproof_s;
    mk_mproof_c_t mk_mproof_c;
    hash_cmp_settings_t hash_cmp;
    pnrg_t pnrg;
    xrn_point_settings_t xrn_point;
    cert_sym_t cert_sym;
    cert_asym_t cert_asym;
    conv_type_t conv_type;
    make_monovalent_key_t xrn_make_monovalent_key;
    monovalent_key_verification_t monovalent_key_verification;
    exchange_polyvalent_key_t exchange_polyvalent_key;
    enc_settings_t enc_settings;
    crc_settings_t crc_settings;
    extract_steganography_block_t extract_steganography_block;
    make_steganography_block_t make_steganography_block;
    extract_steganography_raw_t extract_steganography_raw;
    make_steganography_raw_t make_steganography_raw;
    get_capacity_t get_capacity;
} settings_t;

extern settings_t set;

unsigned int safe_gets( char *str, unsigned int maxsize
 );
int safe_free( void *pt, int size
 );

char getch( int i
 );

#endif
